package com.le.tester.javaThink.fifth.chapter14_StreamingProgramming;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 描述：splitAsStream
 */
public class FileToWordsRegexp {
    private String all;

    public FileToWordsRegexp(String filePath) throws IOException {
        all = Files.lines(Paths.get(filePath))
                //skip first line
                .skip(1)
                .collect(Collectors.joining(","));
    }

    public Stream<String> stream() {
        return Pattern.compile("[ .,?]+").splitAsStream(all);
    }

    public static void main(String[] args) throws IOException {
        FileToWordsBuilder wordsBuilder =
                new FileToWordsBuilder("E:\\L.info\\L.Application\\L.Tester\\src\\main\\java\\com\\le\\tester\\java8\\doc\\Cheese.dat");
//        wordsBuilder.stream()
//                .limit(7)
//                .map(o -> o + " ")
//                .forEach(System.out::print);

        wordsBuilder.stream()
                .skip(7)
                .limit(2)
                .map(o -> o + " ")
                .forEach(System.out::print);
    }
}
